import { getInitApi } from '@/api/login'
const useConfigStore = defineStore('config', {
  state: () => ({
    config: null,
    loadData: null
  }),
  actions: {
    // 获取配置
    getDict(_key) {
      if (!_key || !this.config || !(_key in this.config)) return null
      return this.config[_key]
    },
    // 设置配置
    setConfig(_key, value) {
      if (_key) {
        if (!this.config) this.config = {}
        this.config[_key] = value
      }
    },
    // 删除配置
    removeConfig(_key) {
      if (!_key || !this.config || !(_key in this.config)) return
      delete this.config[_key]
    },
    // 清空配置
    cleanConfig() {
      this.config = null
    },
    // 其他初始加载数据
    dataLoad() {
      return this.loadData
    },
    setLoad(value) {
      this.loadData = value || null
    }
  }
})

export default useConfigStore
